package com.dd.stack.es.pojo.req.complex;

import com.dd.stack.common.util.param.PageParams;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.Instant;
import java.util.List;

/**
 * @Author liuxianmeng
 * @CreateTime 2025/4/20 1:23
 * @Description 电商产品复杂查询请求参数
 */
@Data
@ApiModel(description = "电商产品复杂查询请求参数")
public class ProductQueryReq implements Serializable {
    @ApiModelProperty(value = "分页参数", example = "{\"pageNum\": 0, \"pageSize\": 10}")
    private PageParams pageParams;
    @ApiModelProperty(value = "产品ID精确匹配", example = "prod_0000002")
    private String productId;
    @ApiModelProperty(value = "产品名称模糊查询", example = "Marble Shoes")
    private String name;
    @ApiModelProperty(value = "描述全文检索", example = "aerodynamic")
    private String description;
    @ApiModelProperty(value = "价格区间查询")
    private PriceRange priceRange;
    @ApiModelProperty(value = "库存最小值", example = "100")
    private Integer minStock;
    @ApiModelProperty(value = "是否上架", example = "true")
    private Boolean isActive;
    @ApiModelProperty(value = "创建时间范围")
    private TimeRange createdAtRange;
    @ApiModelProperty(value = "更新时间范围")
    private TimeRange updatedAtRange;
    @ApiModelProperty(value = "分类精确匹配(AND关系)", example = "[\"Clothing\"]")
    private List<String> categories;
    @ApiModelProperty(value = "标签精确匹配(OR关系)", example = "[\"bestseller\", \"sale\"]")
    private List<String> tags;
    @ApiModelProperty(value = "属性嵌套查询条件")
    private List<AttributeQuery> attributes;
    @ApiModelProperty(value = "规格参数查询条件")
    private List<SpecificationQuery> specifications;
    @ApiModelProperty(value = "评价评分最小值", example = "4")
    private Integer minRating;
    @ApiModelProperty(value = "销售数据查询条件")
    private SalesDataQuery salesData;
    @ApiModelProperty(value = "地理位置查询(格式: 经度,纬度 半径km)", example = "57.663185,-38.768638,10")
    private GeoQuery geoQuery;
    @ApiModelProperty(value = "重量范围(kg)")
    private Range<Double> weightRange;
    @ApiModelProperty(value = "尺寸查询条件")
    private DimensionsQuery dimensions;
    @ApiModelProperty(value = "制造商查询条件")
    private ManufacturerQuery manufacturer;
    @ApiModelProperty(value = "产品变体查询条件")
    private List<VariantQuery> variants;
    @ApiModelProperty(value = "排序字段(格式: 字段名,asc/desc)", example = "price,desc")
    private String sort;

    // 嵌套查询条件类
    @Data
    @ApiModel(description = "价格范围查询条件")
    public static class PriceRange {
        @ApiModelProperty(value = "最低价格", example = "100.0")
        private BigDecimal min;
        @ApiModelProperty(value = "最高价格", example = "1000.0")
        private BigDecimal max;
    }

    @Data
    @ApiModel(description = "时间范围查询条件")
    public static class TimeRange {
        @ApiModelProperty(value = "开始时间(ISO格式)", example = "2023-01-01T00:00:00Z")
        private Instant start;
        @ApiModelProperty(value = "结束时间(ISO格式)", example = "2023-12-31T23:59:59Z")
        private Instant end;
    }

    @Data
    @ApiModel(description = "属性查询条件")
    public static class AttributeQuery {
        @ApiModelProperty(value = "属性名称", example = "color")
        private String name;
        @ApiModelProperty(value = "属性值模糊查询", example = "red")
        private String value;
        @ApiModelProperty(value = "是否可见", example = "true")
        private Boolean isVisible;
    }

    @Data
    @ApiModel(description = "规格查询条件")
    public static class SpecificationQuery {
        @ApiModelProperty(value = "规格组名", example = "General")
        private String group;
        @ApiModelProperty(value = "规格项查询条件")
        private List<SpecItemQuery> items;
    }

    @Data
    @ApiModel(description = "规格项查询条件")
    public static class SpecItemQuery {
        @ApiModelProperty(value = "规格键名", example = "material")
        private String key;
        @ApiModelProperty(value = "规格值模糊查询", example = "cotton")
        private String value;
    }

    @Data
    @ApiModel(description = "销售数据查询条件")
    public static class SalesDataQuery {
        @ApiModelProperty(value = "总销量最小值", example = "1000")
        private Integer minTotal;
        @ApiModelProperty(value = "退货率最大值", example = "0.2")
        private Double maxReturnRate;
        @ApiModelProperty(value = "最近30天销量最小值", example = "50")
        private Integer minLast30Days;
    }

    @Data
    @ApiModel(description = "地理位置查询条件")
    public static class GeoQuery {
        @ApiModelProperty(value = "经度", example = "57.663185")
        private Double lon;
        @ApiModelProperty(value = "纬度", example = "-38.768638")
        private Double lat;
        @ApiModelProperty(value = "半径(km)", example = "10")
        private Double radius;
    }

    @Data
    @ApiModel(description = "尺寸查询条件")
    public static class DimensionsQuery {
        @ApiModelProperty(value = "长度范围(mm)")
        private Range<Double> length;
        @ApiModelProperty(value = "宽度范围(mm)")
        private Range<Double> width;
        @ApiModelProperty(value = "高度范围(mm)")
        private Range<Double> height;
    }

    @Data
    @ApiModel(description = "制造商查询条件")
    public static class ManufacturerQuery {
        @ApiModelProperty(value = "制造商名称模糊查询", example = "Goyette")
        private String name;
        @ApiModelProperty(value = "国家精确匹配", example = "Morocco")
        private String country;
        @ApiModelProperty(value = "成立年份范围")
        private Range<Integer> foundedYear;
    }

    @Data
    @ApiModel(description = "产品变体查询条件")
    public static class VariantQuery {
        @ApiModelProperty(value = "颜色精确匹配", example = "Black")
        private String color;
        @ApiModelProperty(value = "尺码精确匹配", example = "XL")
        private String size;
        @ApiModelProperty(value = "库存最小值", example = "10")
        private Integer minStock;
    }

    @Data
    @ApiModel(description = "通用范围查询条件")
    public static class Range<T> {
        private T min;
        private T max;
    }
}